﻿using D.UtilCore;
using D.UtilCore.Dtos;
using D.UtilCore.Filters;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using CozeDto.SaleApplyForDtos;
using CozeDomain.IServices;
using D.UtilFreesqlOrm;

namespace CozeWapApi
{
    /// <summary>
    /// 分销员申请模块
    /// </summary>
    [Route("/api/[controller]/[action]")]
    [Authorize]
    public class SaleApplyForController : BaseApiController
    {
        private readonly ISaleApplyForService _saleApplyForService;
        public SaleApplyForController(ISaleApplyForService saleApplyForService)
        {
            _saleApplyForService = saleApplyForService;
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="reqAddSaleApplyFor"></param>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<int>> Add([FromBody] ReqAddSaleApplyFor reqAddSaleApplyFor)
        {
            reqAddSaleApplyFor.CreateUser = Account;
            return await _saleApplyForService.AddSaleApplyForAsync(reqAddSaleApplyFor);
        }

        /// <summary>
        /// 我的申请记录
        /// </summary>
        /// <returns></returns>
        [HttpGet, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<List<RepSaleApplyForInfo>>> List()
        {
            return await _saleApplyForService.GetSaleApplyForListAsync(LoginId);
        }
    } 
}
